import pandas as pd
import sys
import os

Base_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
Base_In = Base_DIR + "\in"
Base_Out = Base_DIR + "\out"
print("文件路径：" + Base_DIR)

files = os.listdir(Base_In)
s = []
for file in files:
    file_name = os.path.splitext(file)
    print("文件名：" + file)
    print("(文件名, 文件后缀格式) ==> " + file_name)
    if file_name[1] == '.xlsx' or file_name[1] == '.xls':
        print("开始执行转换：文件为-" + str(file))
        file_addr = Base_In + "/" + file

        sheet_len = len(pd.ExcelFile(file_addr).sheet_names)
        # 指定下标读取
        for i in range(0, sheet_len):
            df = pd.read_excel(file_addr, sheet_name=i, header=None)
            df.to_csv(Base_Out + "/" + file_name[0] + "_Sheet" + str(i+1) + ".txt", header=None, sep='\t', index=False)
            print("转换成功：文件为-" + str(file_name[0] + ".txt"))